package com.czy.fx.swingNode;

import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

import javax.swing.*;
import java.awt.*;
/*
  fx加载swing组件示例
 */
public class Demo extends Application {
    public static void main(String[] args) {
        launch(args);
    }
    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane pane = new AnchorPane();
        pane.setPrefSize(600, 400);
        Scene scene = new Scene(pane);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Hello World");
        primaryStage.show();

        SwingNode swingNode = new SwingNode();
        pane.getChildren().add(swingNode);

        SwingUtilities.invokeLater(()->{
            JPanel jPanel = new JPanel();
            jPanel.setLayout(new FlowLayout());
            JButton b1 = new JButton("按钮1");
            JButton b2 = new JButton("按钮2");
            jPanel.add(b1);
            jPanel.add(b2);
            swingNode.setContent(jPanel);
        });


    }
}
